
version 14.2
clear
log using "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\ch7_figures.log", replace
set more off

use "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\ch7.dta", clear


**** Impact of Corruption on Incumbent Vote

**** National Vote Figure 7.4

*** IDF national
logit INCUMBENT nationalcorrupt i.partyID i.opposeID if ELECID==5  
margins, at(nationalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(IDF, replace)

*** Provence national
logit INCUMBENT nationalcorrupt  i.partyID i.opposeID if ELECID==6 
margins, at(nationalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(provence, replace)

*** Catalonia national
logit INCUMBENT nationalcorrupt  i.partyID i.opposeID if ELECID==7 
margins, at(nationalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(cataloniaN, replace)

*** Madrid national
logit INCUMBENT nationalcorrupt  i.partyID i.opposeID if ELECID==9 
margins, at(nationalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(madridN, replace)

*** Lower Saxony
logit INCUMBENT nationalcorrupt   i.partyID i.opposeID if ELECID==10
margins, at(nationalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(saxonyN, replace)

*** Bavaria national
logit INCUMBENT nationalcorrupt i.partyID i.opposeID if ELECID==12
margins, at(nationalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(bavariaN, replace)

gr combine IDF.gph provence.gph cataloniaN.gph madridN.gph bavariaN.gph saxonyN.gph , col(2) ysize(2) xsize(2)

graph save "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\fig7_4.gph", replace

********************************************************

**** Subnational Vote Figure 7.5

*** Paris 
logit INCUMBENT municipalcorrupt  i.partyID i.opposeID if ELECID==22
margins, at(municipalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(paris, replace)

*** Marseille
logit INCUMBENT municipalcorrupt i.partyID i.opposeID if ELECID==23  
margins, at(municipalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(marseille, replace)

*** Catalonia subnational
logit INCUMBENT regionalcorrupt  i.partyID i.opposeID if ELECID==8 
margins, at(regionalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(cataloniaS, replace)

*** Madrid subnational
logit INCUMBENT regionalcorrupt  i.partyID i.opposeID if ELECID==24 
margins, at(regionalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(madridS, replace)

*** Bavaria subnational
logit INCUMBENT regionalcorrupt  i.partyID i.opposeID if ELECID==13
margins, at(regionalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(bavariaS, replace)

**** Lower Saxony subnational
logit INCUMBENT regionalcorrupt   i.partyID i.opposeID if ELECID==11
margins, at(regionalcorrupt=(0 (1) 3))
marginsplot, recast(line) recastci(rarea) saving(saxonyS, replace)

gr combine paris.gph marseille.gph cataloniaS.gph madridS.gph bavariaS.gph saxonyS.gph , col(2) ysize(2) xsize(2)


graph save "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\fig7_5.gph", replace


********************************************************


**** Examining Impact of Cross-level Corruption Perceptions Figure 6

**** National Vote

*** IDF national
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt municipalcorrupt i.partyID i.opposeID if ELECID==5  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=municipalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==5  
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "municipal") saving(CIDF, replace)

drop corrupt

*** Provence national
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt municipalcorrupt i.partyID i.opposeID if ELECID==6 
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=municipalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==6  
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "municipal") saving(Cprovence, replace)

drop corrupt

*** Catalonia national
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt regionalcorrupt i.partyID i.opposeID if ELECID==7  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=regionalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==7  
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "subnational") saving(Ccatalonia, replace)

drop corrupt

*** Madrid national
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt regionalcorrupt i.partyID i.opposeID if ELECID==9  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=regionalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==9  
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "subnational") saving(Cmadrid, replace)

drop corrupt

*** Lower Saxony nationa
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt regionalcorrupt i.partyID i.opposeID if ELECID==10  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=regionalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==10 
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "subnational") saving(Csaxony, replace)

drop corrupt

*** Bavaria national
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt regionalcorrupt i.partyID i.opposeID if ELECID==12  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=regionalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==12 
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "subnational") saving(Cbavaria, replace)

drop corrupt

gr combine CIDF.gph CProvence.gph Ccatalonia.gph Cmadrid.gph Cbavaria.gph Csaxony.gph , col(2) ysize(2) xsize(2)

graph save "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\fig7_6.gph", replace

********************************************************

**** Subnational Vote Figure 7

*** Marseille
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt municipalcorrupt i.partyID i.opposeID if ELECID==23  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=municipalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==23  
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "municipal") saving(CMarseille, replace)

drop corrupt

*** Paris
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt municipalcorrupt i.partyID i.opposeID if ELECID==22  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=municipalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==22 
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "municipal") saving(CParis, replace)

drop corrupt

*** Catalonia subnational
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt regionalcorrupt i.partyID i.opposeID if ELECID==8  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=regionalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==8 
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "municipal") saving(CcataloniaS, replace)

drop corrupt

*** Madrid subnational
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt regionalcorrupt i.partyID i.opposeID if ELECID==24  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=regionalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==24 
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "municipal") saving(CmadridS, replace)

drop corrupt

**** Lower Saxony subnational
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt regionalcorrupt i.partyID i.opposeID if ELECID==11  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=regionalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==11
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "municipal") saving(CsaxonyS, replace)

drop corrupt

*** Bavaria subnational
gen corrupt=nationalcorrupt
logit INCUMBENT corrupt regionalcorrupt i.partyID i.opposeID if ELECID==13  
margins, at(corrupt=(0 (1) 3)) saving(file1, replace)

drop corrupt
gen corrupt=regionalcorrupt
logit INCUMBENT corrupt nationalcorrupt i.partyID i.opposeID if ELECID==13
margins, at(corrupt=(0 (1) 3))saving(file2, replace)

combomarginsplot file1 file2, recast(line) recastci(rarea) label("national" "municipal") saving(CbavariaS, replace)

drop corrupt


gr combine CParis.gph CMarseille.gph CcataloniaS.gph CmadridS.gph CbavariaS.gph CsaxonyS.gph , col(2) ysize(2) xsize(2)

graph save "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\fig7_7.gph", replace

********************************************************

*** Economic Evaluations Figure 1

* Graph - National Economy 

preserve 
drop if inlist(nationaleconomy, 9, .) 
keep if inlist(ELECID, 5, 6, 7, 9, 10, 12) 
proportion nationaleconomy, over(ELECID) 
matrix forgraph = r(table)
matrix list forgraph
clear 
input ELECID nationaleconomy  
5 1
5 2
5 3 
6 1
6 2
6 3
7 1 
7 2
7 3
9 1
9 2
9 3
10 1
10 2
10 3
12 1
12 2 
12 3 
end
gen share = .
replace share = forgraph[1,1] if ELECID == 5 & nationaleconomy == 1
replace share = forgraph[1,2] if ELECID == 6 & nationaleconomy == 1
replace share = forgraph[1,3] if ELECID == 7 & nationaleconomy == 1
replace share = forgraph[1,4] if ELECID == 9 & nationaleconomy == 1
replace share = forgraph[1,5] if ELECID == 10 & nationaleconomy == 1
replace share = forgraph[1,6] if ELECID == 12 & nationaleconomy == 1
replace share = forgraph[1,7] if ELECID == 5 & nationaleconomy == 2
replace share = forgraph[1,8] if ELECID == 6 & nationaleconomy == 2
replace share = forgraph[1,9] if ELECID == 7 & nationaleconomy == 2
replace share = forgraph[1,10] if ELECID == 9 & nationaleconomy == 2
replace share = forgraph[1,11] if ELECID == 10 & nationaleconomy == 2
replace share = forgraph[1,12] if ELECID == 12 & nationaleconomy == 2
replace share = forgraph[1,13] if ELECID == 5 & nationaleconomy == 3
replace share = forgraph[1,14] if ELECID == 6 & nationaleconomy == 3
replace share = forgraph[1,15] if ELECID == 7 & nationaleconomy == 3
replace share = forgraph[1,16] if ELECID == 9 & nationaleconomy == 3
replace share = forgraph[1,17] if ELECID == 10 & nationaleconomy == 3
replace share = forgraph[1,18] if ELECID == 12 & nationaleconomy == 3
replace share = share * 100 // to get percentages
recode ELECID (5=1 "IDF") (6=2 "Provence") (7=3 "Catalonia") (9=4 "Madrid") ///
(12=5 "Bavaria") (10=6 "Lower Saxony"), gen(region)
label variable region Region 
replace region = cond(nationaleconomy == 1, region - 0.3, region + 0)
replace region = cond(nationaleconomy == 3, region + 0.3, region + 0)
replace share = round(share, .1)
tostring share, gen(barlabels) force
replace barlabels = substr(barlabels, 1, 4)
replace barlabels = "5.8" if barlabels == "5.80"
replace barlabels = "2.2" if barlabels == "2.20"
replace barlabels = "1.6" if barlabels == "1.60"
replace barlabels = "33.0" if barlabels == "33"
replace barlabels = barlabels+" "+"%" 
cap ssc install mylabels 
mylabels 0(10)90, local(labels) myscale(@) suffix(" %")
twoway bar share region if nationaleconomy==1, color(gs4) barwidth(0.3) lpattern(l) lcolor(gs0) || ///
       bar share region if nationaleconomy==2, color(gs10) barwidth(0.3) lpattern(l) lcolor(gs0) ||  ///
	   bar share region if nationaleconomy==3, color(gs13) barwidth(0.3) ||  ///
	   scatter share region if nationaleconomy==1, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(small) || ///
       scatter share region if nationaleconomy==2, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(small)||  ///
	   scatter share region if nationaleconomy==3, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(small) ///
	   ylabel(`labels') ///
	   legend(row(1) order(1 "Worse" 2 "About the same" 3 "Better")) lpattern(l) lcolor(gs0) ///   
	   xlabel(2"Provence" 1`" "Ile de" "France" "' 3"Catalonia" 4"Madrid" 5"Bavaria" 6`" "Lower" "Saxony" "') ///
	   ytitle("") scale(0.8)  yscale(range(0(10)90)) saving(nationaleconomy, replace)
restore


*** Graph Subnational Economy

preserve 
drop if inlist(regionaleconomy, 9, .) 
keep if inlist(ELECID, 8, 11, 13, 22, 23) 
proportion regionaleconomy, over(ELECID) 
matrix forgraph = r(table)
matrix list forgraph
clear 
input ELECID regionaleconomy  
8 1
8 2
8 3 
11 1 
11 2
11 3
13 1
13 2
13 3
22 1
22 2
22 3
23 1
23 2 
23 3 
end
gen share = .
replace share = forgraph[1,1] if ELECID == 8 & regionaleconomy == 1
replace share = forgraph[1,2] if ELECID == 11 & regionaleconomy == 1
replace share = forgraph[1,3] if ELECID == 13 & regionaleconomy == 1
replace share = forgraph[1,4] if ELECID == 22 & regionaleconomy == 1
replace share = forgraph[1,5] if ELECID == 23 & regionaleconomy == 1
replace share = forgraph[1,6] if ELECID == 8 & regionaleconomy == 2
replace share = forgraph[1,7] if ELECID == 11 & regionaleconomy == 2
replace share = forgraph[1,8] if ELECID == 13 & regionaleconomy == 2
replace share = forgraph[1,9] if ELECID == 22 & regionaleconomy == 2
replace share = forgraph[1,10] if ELECID == 23 & regionaleconomy == 2
replace share = forgraph[1,11] if ELECID == 8 & regionaleconomy == 3
replace share = forgraph[1,12] if ELECID == 11 & regionaleconomy == 3
replace share = forgraph[1,13] if ELECID == 13 & regionaleconomy == 3
replace share = forgraph[1,14] if ELECID == 22 & regionaleconomy == 3
replace share = forgraph[1,15] if ELECID == 23 & regionaleconomy == 3
replace share = share * 100 // to get percentages
recode ELECID (22=1 "Paris") (23=2 "Marseille") (8=3 "Catalonia")  ///
(13=4 "Bavaria") (11=5 "Lower Saxony"), gen(region)
label variable region Region 
replace region = cond(regionaleconomy == 1, region - 0.3, region + 0)
replace region = cond(regionaleconomy == 3, region + 0.3, region + 0)
replace share = round(share, .1)
tostring share, gen(barlabels) force
replace barlabels = substr(barlabels, 1, 4)
replace barlabels = "5.8" if barlabels == "5.80"
replace barlabels = "2.2" if barlabels == "2.20"
replace barlabels = "1.6" if barlabels == "1.60"
replace barlabels = "33.0" if barlabels == "33"
replace barlabels = barlabels+" "+"%" 
cap ssc install mylabels 
mylabels 0(10)90, local(labels) myscale(@) suffix(" %")
twoway bar share region if regionaleconomy==1, color(gs4) barwidth(0.3) lpattern(l) lcolor(gs0) || ///
       bar share region if regionaleconomy==2, color(gs10) barwidth(0.3) lpattern(l) lcolor(gs0) ||  ///
	   bar share region if regionaleconomy==3, color(gs13) barwidth(0.3) ||  ///
	   scatter share region if regionaleconomy==1, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(small) || ///
       scatter share region if regionaleconomy==2, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(small)||  ///
	   scatter share region if regionaleconomy==3, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(small) ///
	   ylabel(`labels') ///
	   legend(row(1) order(1 "Worse" 2 "About the same" 3 "Better")) lpattern(l) lcolor(gs0) ///   
	   xlabel(2"Marseille" 1"Paris" 3"Catalonia" 4"Bavaria" 5`" "Lower" "Saxony" "') ///
	   ytitle("") scale(0.8)  yscale(range(0(10)90)) fxsize(120) saving(subnationalgraph1, replace) 
restore



gr combine nationaleconomy.gph subnationalgraph1.gph, ysize(2) xsize(3) col(1)

graph save "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\fig7_1.gph", replace

********************************************************

**** Attributions of Responsibility Figure 2

**** National Economy
preserve
keep if inlist(ELECID, 5, 6, 7, 9, 10, 12) 
proportion nationalresponsibility, over(ELECID) 
matrix forgraph = r(table)
matrix list forgraph
clear 
input ELECID nationalresponsibility
5 1
5 2
5 3 
6 1
6 2
6 3
7 1 
7 2
7 3
9 1
9 2
9 3
10 1
10 2
10 3
12 1
12 2 
12 3 
end
gen share = .
replace share = forgraph[1,1] if ELECID == 5 & nationalresponsibility == 1
replace share = forgraph[1,2] if ELECID == 6 & nationalresponsibility == 1
replace share = forgraph[1,3] if ELECID == 7 & nationalresponsibility == 1
replace share = forgraph[1,4] if ELECID == 9 & nationalresponsibility == 1
replace share = forgraph[1,5] if ELECID == 10 & nationalresponsibility == 1
replace share = forgraph[1,6] if ELECID == 12 & nationalresponsibility == 1
replace share = forgraph[1,7] if ELECID == 5 & nationalresponsibility == 2
replace share = forgraph[1,8] if ELECID == 6 & nationalresponsibility == 2
replace share = forgraph[1,9] if ELECID == 7 & nationalresponsibility == 2
replace share = forgraph[1,10] if ELECID == 9 & nationalresponsibility == 2
replace share = forgraph[1,11] if ELECID == 10 & nationalresponsibility == 2
replace share = forgraph[1,12] if ELECID == 12 & nationalresponsibility == 2
replace share = forgraph[1,13] if ELECID == 5 & nationalresponsibility == 3
replace share = forgraph[1,14] if ELECID == 6 & nationalresponsibility == 3
replace share = forgraph[1,15] if ELECID == 7 & nationalresponsibility == 3
replace share = forgraph[1,16] if ELECID == 9 & nationalresponsibility == 3
replace share = forgraph[1,17] if ELECID == 10 & nationalresponsibility == 3
replace share = forgraph[1,18] if ELECID == 12 & nationalresponsibility == 3
replace share = share * 100 // to get percentages
recode ELECID (5=1 "IDF") (6=2 "Provence") (7=3 "Catalonia") (9=4 "Madrid") ///
(12=5 "Bavaria") (10=6 "Lower Saxony"), gen(region)
label variable region Region 
replace region = cond(nationalresponsibility == 1, region - 0.3, region + 0)
replace region = cond(nationalresponsibility == 3, region + 0.3, region + 0)
replace share = round(share, .1)
tostring share, gen(barlabels) force
replace barlabels = substr(barlabels, 1, 4)
replace barlabels = "5.8" if barlabels == "5.80"
replace barlabels = "2.2" if barlabels == "2.20"
replace barlabels = "1.6" if barlabels == "1.60"
replace barlabels = "33.0" if barlabels == "33"
replace barlabels = barlabels // +" "+"%" 
cap ssc install mylabels 
mylabels 0(10)90, local(labels) myscale(@) suffix(" %")
twoway bar share region if nationalresponsibility==1, color(gs4) barwidth(0.3) lpattern(l) lcolor(gs0) || ///
       bar share region if nationalresponsibility==2, color(gs10) barwidth(0.3) lpattern(l) lcolor(gs0) ||  ///
	   bar share region if nationalresponsibility==3, color(gs13) barwidth(0.3) ||  ///
	   scatter share region if nationalresponsibility==1, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(vsmall) || ///
       scatter share region if nationalresponsibility==2, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(vsmall)||  ///
	   scatter share region if nationalresponsibility==3, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(vsmall) ///
	   ylabel(`labels') ///
	   legend(row(3) order(1 "worse" 2 "not much difference" 3 "better"))  lpattern(l) lcolor(gs0) ///   
	   xlabel(2"Provence" 1`" "Ile de" "France" "' 3"Catalonia" 4"Madrid" 5"Bavaria" 6`" "Lower" "Saxony" "') ///
	   ytitle("") scale(0.8) xtitle("Region", margin(medium)) yscale(range(0(10)90)) name(right_graph, replace) fxsize(150) ///
	   title("The National Economy") 
restore

**** Subnational Economy
preserve
keep if inlist(ELECID, 8, 11, 13)  
proportion regionalresponsibility, over(ELECID) 
matrix forgraph = r(table)
matrix list forgraph
clear 
input ELECID regonalresponsibility 
8 1
8 2
8 3 
11 1
11 2
11 3
13 1 
13 2
13 3
end
gen share = .
replace share = forgraph[1,1] if ELECID == 8 & regonalresponsibility == 1
replace share = forgraph[1,2] if ELECID == 11 & regonalresponsibility == 1
replace share = forgraph[1,3] if ELECID == 13 & regonalresponsibility == 1
replace share = forgraph[1,4] if ELECID == 8 & regonalresponsibility == 2
replace share = forgraph[1,5] if ELECID == 11 & regonalresponsibility == 2
replace share = forgraph[1,6] if ELECID == 13 & regonalresponsibility == 2
replace share = forgraph[1,7] if ELECID == 8 & regonalresponsibility == 3
replace share = forgraph[1,8] if ELECID == 11 & regonalresponsibility == 3
replace share = forgraph[1,9] if ELECID == 13 & regonalresponsibility == 3
replace share = share * 100 // to get percentages
recode ELECID (8=1 "Catalonia") (11=3 "Lower Saxony") (13=2 "Bavaria"), gen(region)
label variable region Region 
replace region = cond(regonalresponsibility == 1, region - 0.3, region + 0)
replace region = cond(regonalresponsibility == 3, region + 0.3, region + 0)
replace share = round(share, .1)
cap drop barlabels
tostring share, gen(barlabels) force
replace barlabels = substr(barlabels, 1, 4)
/*replace barlabels = "5.8" if barlabels == "5.80"
replace barlabels = "2.2" if barlabels == "2.20"
replace barlabels = "1.6" if barlabels == "1.60"
replace barlabels = "33.0" if barlabels == "33"*/
replace barlabels = barlabels // +" "+"%" 
cap ssc install mylabels 
mylabels 0(10)90, local(labels) myscale(@) suffix(" %")
twoway bar share region if regonalresponsibility==1, color(gs4) barwidth(0.3) lpattern(l) lcolor(gs0) || ///
       bar share region if regonalresponsibility==2, color(gs10) barwidth(0.3) lpattern(l) lcolor(gs0) ||  ///
	   bar share region if regonalresponsibility==3, color(gs13) barwidth(0.3) ||  ///
	   scatter share region if regonalresponsibility==1, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(vsmall) || ///
       scatter share region if regonalresponsibility==2, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(vsmall)||  ///
	   scatter share region if regonalresponsibility==3, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(vsmall) ///
	   ylabel(`labels') ///
	   legend(row(3) order(1 "worse" 2 "not much difference" 3 "same"))  lpattern(l) lcolor(gs0) ///   
	   xlabel(1"Catalonia"  2"Bavaria" 3`" "Lower" "Saxony" "') ///
	   ytitle("") scale(0.8) xtitle("Region", margin(medium)) yscale(range(0(10)90)) name(left_graph, replace) fxsize(85) ///
	   title("The Subnational Economy") 
restore

graph combine right_graph left_graph, col(2)

graph save "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\fig7_2.gph", replace

********************************************************

**** Corruption Figure 3
replace regionalcorrupt=municipalcorrupt if ELECID==22
replace regionalcorrupt=municipalcorrupt if ELECID==23

preserve 
keep if inlist(ELECID, 5, 6, 7, 9, 10, 12) 
proportion Q50B, over(ELECID)
matrix forgraph_national = r(table)
matrix list forgraph_national 
restore 

preserve 

keep if inlist(ELECID, 8, 11, 13, 22, 23, 24) 
rename ELECID temp1
recode temp1 (22=5) (23=6) (8=7) (24=9) (11=10) (13=12), gen(ELECID) 
proportion Q50A, over(ELECID) 
matrix forgraph_regional = r(table)
matrix list forgraph_regional 
restore 


preserve 
clear 
input ELECID national  
5 1
5 0 
6 1
6 0
7 1 
7 0
9 1
9 0
10 1
10 0
12 1
12 0 
end
gen share = .
replace share = forgraph_regional[1,19] if ELECID == 5 & national == 0 
replace share = forgraph_regional[1,20] if ELECID == 6 & national == 0
replace share = forgraph_regional[1,21] if ELECID == 7 & national == 0
replace share = forgraph_regional[1,22] if ELECID == 9 & national == 0
replace share = forgraph_regional[1,23] if ELECID == 10 & national == 0
replace share = forgraph_regional[1,24] if ELECID == 12 & national == 0
replace share = forgraph_national[1,19] if ELECID == 5 & national == 1
replace share = forgraph_national[1,20] if ELECID == 6 & national == 1
replace share = forgraph_national[1,21] if ELECID == 7 & national == 1
replace share = forgraph_national[1,22] if ELECID == 9 & national == 1
replace share = forgraph_national[1,23] if ELECID == 10 & national == 1
replace share = forgraph_national[1,24] if ELECID == 12 & national == 1
replace share = share * 100 // to get percentages
recode ELECID (5=1 "IDF") (6=2 "Provence") (7=3 "Catalonia") (9=4 "Madrid") ///
(12=5 "Bavaria") (10=6 "Lower Saxony"), gen(region)
label variable region Region 
replace region = cond(national == 0, region - 0.15, region + 0)
replace region = cond(national == 1, region + 0.15, region + 0)
replace share = round(share, .1)
tostring share, gen(barlabels) force
replace barlabels = substr(barlabels, 1, 4)
*replace barlabels = "rounded value to one decimal" if barlabels == "original form" // if you want to have the same number of decimal places
*replace barlabels = barlabels // +" "+"%" 
cap ssc install mylabels 
mylabels 0(10)60, local(labels) myscale(@) suffix(" %")
twoway  bar share region if national==0, color(gs10) barwidth(0.3) lpattern(l) lcolor(gs0) ||  ///
		bar share region if national==1, color(gs4) barwidth(0.3) lpattern(l) lcolor(gs0) || ///
	    scatter share region if national==0, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(vsmall)  || ///
	   scatter share region if national==1, msym(none) mlab(barlabels) mlabpos(12) mlabcolor(black) mlabs(vsmall) ///
	   ylabel(`labels') ///
	   legend(row(1) order(1 "Subnational" 2 "National")) lpattern(l) lcolor(gs0) ///   
	   xlabel(2"Provence" 1`" "Ile de" "France" "' 3"Catalonia" 4"Madrid" 5"Bavaria" 6`" "Lower" "Saxony" "') ///
	   ytitle("") scale(0.8) xtitle(("Region"), margin(medium)) yscale(range(0(10)60)) fxsize(150) ///
	   title("") 


graph save "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\fig7_3.gph", replace

restore

log close
exit
